//
//  DataErrorView.swift
//  SwiftScienceChina
//
//  Created by 贾培军 on 2019/12/12.
//  Copyright © 2019 贾培军. All rights reserved.
//

import UIKit

open class SWDataErrorView: UIView {

   var contentView = UIView()
   var iconView = UIImageView()
   var retryLabel = UILabel()
   var title: String?{
       set{
           self.retryLabel.text = newValue
       }
       get{
           return self.retryLabel.text
       }
   }
   var retryBlock: RetryBlock?
   var attributedTitle: NSAttributedString?{
       set{
           self.retryLabel.attributedText = newValue
       }
       get{
           return self.retryLabel.attributedText
       }
   }
   override init(frame: CGRect) {
       super.init(frame: frame)
       setupUI()
       setupLayout()
   }
   public required init?(coder: NSCoder) {
       super.init(coder: coder)
   }
   @objc func retry(){
       retryBlock!()
   }
   func setupUI(){
       self.backgroundColor = .init(0xe6e6e6)
       contentView.backgroundColor = .white
       
       //        iconView.image  = .init(imageLiteralResourceName: "哭脸")
       
       retryLabel.font = UIFont.systemFont(ofSize: 14)
       retryLabel.textColor = .init(999999)
       retryLabel.text = "数据错误"
       
       let tap = UITapGestureRecognizer(target: self, action:#selector(self.retry))
       self.addGestureRecognizer(tap)
   }
   func setupLayout(){
       self.addSubview(contentView)
       contentView.snp.makeConstraints { (m) in
           m.edges.equalTo(10)
       }
       
       contentView.addSubview(iconView)
       iconView.snp.makeConstraints { (m) in
           m.centerX.equalTo(self)
           m.centerY.equalTo(self).offset(-55)
           m.width.height.equalTo(75)
       }
       
       contentView.addSubview(retryLabel)
       retryLabel.snp.makeConstraints { (m) in
           m.centerX.equalTo(self)
           m.top.equalTo(iconView.snp.bottom).offset(10)
       }
   }

}
